package com.yunsom.testdemo.design.adapter;

/**
 * @author Xbao
 * @description 适配器类
 * @date 2022/6/20 13:56
 */
public class MediaAdapter implements MediaPlayer{

  AdvancedMediaPlayer advancedMediaPlayer;

  public MediaAdapter(String audioType){
    if("mp3".equalsIgnoreCase(audioType)){
      advancedMediaPlayer = new Mp3Player();
    } else if("mp4".equalsIgnoreCase(audioType)){
      advancedMediaPlayer = new Mp4Player();
    }
  }

  @Override
  public void play(String audioType, String fileName) {
    if("mp3".equalsIgnoreCase(audioType)){
      advancedMediaPlayer.playMp3(fileName);
    } else if("mp4".equalsIgnoreCase(audioType)){
      advancedMediaPlayer.playMp4(fileName);
    }
  }
}
